package remote.adapters;

import remote.activities.R;
import remote.controllers.BaseController;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FilesArrayAdapter extends ArrayAdapter<String>
{
	private Context _context;
	private BaseController _controller;
	private String[] _files;
	
	public FilesArrayAdapter(Context context, BaseController controller, String[] files)
	{
		super(context, R.layout.file_browser_row_layout, files);
		
		_context = context;
		_controller = controller;
		_files = files;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		LayoutInflater inflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View rowView = inflater.inflate(R.layout.file_browser_row_layout, parent, false);
		TextView txtFile = (TextView) rowView.findViewById(R.id.file_browser_lblFile);
		ImageView imgIcon = (ImageView) rowView.findViewById(R.id.file_browser_imgFile);
		txtFile.setText(_files[position]);
		
		if (_files[position].matches("^.*\\.[a-zA-Z0-9]{0,4}$"))
			imgIcon.setImageResource(R.drawable.ic_media_ff);
		else
			imgIcon.setImageResource(R.drawable.ic_menu_folder);

		return rowView;
	}
}
